import SettingHelperBase from "./SettingHelperBase";
import ccclass = cc._decorator.ccclass;
@ccclass
export class DefaultSettingHelper extends SettingHelperBase{
    get Count(): number {
        return cc.sys.localStorage.length;
    }

    GetAllSettingNames(): string[] {
        let result = [];
        for (let i = 0; i < cc.sys.localStorage.length;i++){
            let settingName:string = cc.sys.localStorage.key(i);
            result.push(settingName);
        }
        return result;
    }

    GetBool(settingName: string): boolean {
        return cc.sys.localStorage.getItem(settingName);
    }

    GetNumber(settingName: string): number {
        return cc.sys.localStorage.getItem(settingName);
    }

    GetObject(settingName: string): any {
        let obj = cc.sys.localStorage.getItem(settingName);
        return JSON.parse(obj);
    }

    GetString(settingName: string): string {
        return cc.sys.localStorage.getItem(settingName);
    }

    HasSetting(settingName: string): boolean {
        return cc.sys.localStorage.getItem(settingName) == null;
    }

    Load(): boolean {
        return true;
    }

    RemoveAllSettings(): void {
        cc.sys.localStorage.clear();
    }

    RemoveSetting(settingName: string): boolean {
        cc.sys.localStorage.removeItem(settingName);
        return true;
    }

    Save(): boolean {
        return true;
    }

    SetBool(settingName: string, value: boolean): void {
        cc.sys.localStorage.setItem(settingName,value);
    }

    SetNumber(settingName: string, value: number): void {
        cc.sys.localStorage.setItem(settingName,value);
    }

    SetObject(settingName: string, obj: any): void {
        let value:string = JSON.stringify(obj);
        cc.sys.localStorage.setItem(settingName,value);
    }

    SetString(settingName: string, value: string): void {
        cc.sys.localStorage.setItem(settingName,value);
    }

}